package com.happystudy.controller;

import com.happpystudy.model.University;
import com.happpystudy.service.UniversityService;
import com.happystudy.message.BaseMessageModel;
import com.happystudy.message.ErrorMessage;
import com.happystudy.message.ErrorMessageType;
import com.happystudy.message.SingleDataMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author LYJ
 */
@RestController
public class UniversityController {

    @Autowired
    UniversityService universityService;


    @GetMapping("/university/{uniName}")
    public BaseMessageModel getUniversityIdByName(@PathVariable(value = "uniName") String uniName) {
        System.out.println(uniName);
        University university =  universityService.getUniversityIdByName(uniName);
        System.out.println(university);
        BaseMessageModel message;
        if (university != null) {
            message = new SingleDataMessage(university);
        }else{
            message = new ErrorMessage(ErrorMessageType.UNIVERSITY_NOT_FOUND_CODE,ErrorMessageType.UNIVERSITY_NOT_FOUND_MSG);
        }
        return message;
    }

}
